package com.runner.track;

import com.badlogic.gdx.math.Vector2;
import com.runner.entity.CollisionEntity;
import com.runner.player.Player;
import com.runner.utility.Locator;

public class MovingBlock extends Block{

	public static final float VERTICAL_SPEED=20 * RELATIVE_SPEED;
	private float speed;
	
	public MovingBlock(Vector2 pos, boolean up) {
		super(pos, TYPE.BLOCK, BLOCK_STONE_PATH, SCALE);
		speed=VERTICAL_SPEED*Locator.getYGameSpeed();
		if(!up){
			speed*=-1;
		}
	}
	
	public void update(float delta){
		super.update(delta);
		//start moving once it reaches 3 block widths from right of screen
		if(physics.getBody().getPosition().x <= (VIRTUAL_WIDTH*Locator.getxSpriteScale() - (3*BLOCK_WIDTH*Locator.getxSpriteScale()))){
			physics.getBody().setLinearVelocity(physics.getBody().getLinearVelocity().x,speed*delta);
		}
		/*if(physics.getBody().getPosition().y < 0 ){
			speed=0;
		}*/
		if(!exists || physics.getBody().getPosition().x < -BLOCK_WIDTH * Locator.getxSpriteScale()){
			delete();
			exists=false;
		}
	}

	@Override
	public void collide(CollisionEntity otherBody) {
		if(otherBody.getPhysics().getType().equals(TYPE.PLAYER)){
			if(!((Player)otherBody).hasShield()){
				exists=false;
			}
		}
	}

}
